//
//  MessageTopView.m
//  PYWGetColor
//
//  Created by 杜文杰 on 2018/6/15.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "MessageTopView.h"

#define MARGINWIDTH 10
@interface MessageTopView()

@end

@implementation MessageTopView
- (void)firstAction:(UIButton *)btn
{
    NSLog(@"啊啊啊");
    if ([btn isEqual:self.firstBtn]) {
        [self.secondBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
        [self.secondBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        self.secondBtn.selected = NO;
        self.firstBtn.selected = !self.firstBtn.selected;
        if (self.firstBtn.isSelected) {
            [self.firstBtn setImage:[UIImage imageNamed:@"list_sj.2"] forState:UIControlStateNormal];
            [self.firstBtn setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        }else{
            [self.firstBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
            [self.firstBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        }
        self.btnTagBlock(@"1");
    }
    if ([btn isEqual:self.secondBtn]) {
        [self.firstBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
        [self.firstBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        self.firstBtn.selected = NO;
        self.secondBtn.selected = !self.secondBtn.selected;
        if (self.secondBtn.isSelected) {
            [self.secondBtn setImage:[UIImage imageNamed:@"list_sj.2"] forState:UIControlStateNormal];
            [self.secondBtn setTitleColor:getColor(mainColor) forState:UIControlStateNormal];
        }else{
            [self.secondBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
            [self.secondBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        }
        self.btnTagBlock(@"2");
    }
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpView];
    }
    return self;
}
- (void)setUpView
{
    UIButton *firstBtn = [[UIButton alloc]init];
    firstBtn.backgroundColor = [UIColor clearColor];
    [firstBtn setTitle:@"系统消息" forState:UIControlStateNormal];
    [firstBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
    [firstBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
    [firstBtn addTarget:self action:@selector(firstAction:) forControlEvents:UIControlEventTouchUpInside];
    [firstBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -135 / WIDTH_6S_SCALE)];
    [firstBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20 / WIDTH_6S_SCALE, 0, 0)];
    firstBtn.titleLabel.font = DEF_FontSize_14;
    self.firstBtn = firstBtn;
    [self addSubview:firstBtn];
    
    UIButton *secondBtn = [[UIButton alloc]init];
    secondBtn.backgroundColor = [UIColor clearColor];
    [secondBtn setTitle:@"聊天互动" forState:UIControlStateNormal];
    [secondBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
    [secondBtn setImage:[UIImage imageNamed:@"list_sj.1"] forState:UIControlStateNormal];
    [secondBtn addTarget:self action:@selector(firstAction:) forControlEvents:UIControlEventTouchUpInside];
    [secondBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -135 / WIDTH_6S_SCALE)];
    [secondBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20 / WIDTH_6S_SCALE, 0, 0)];
    secondBtn.titleLabel.font = DEF_FontSize_14;
    self.secondBtn = secondBtn;
    [self addSubview:secondBtn];
    
    __weak typeof(self)weakself = self;
    [firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakself.mas_centerY);
        make.left.equalTo(weakself.mas_left).offset(10 / WIDTH_6S_SCALE);
        make.width.mas_equalTo((SCREEN_WIDTH - 3 * MARGINWIDTH) / 2 );
        make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
    }];
    [secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakself.mas_centerY);
        make.left.equalTo(firstBtn.mas_right).offset(10 / WIDTH_6S_SCALE);
        make.width.mas_equalTo((SCREEN_WIDTH - 3 * MARGINWIDTH) / 2 );
        make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
    }];
    UIView *lineView1 = [[UIView alloc]init];
    lineView1.backgroundColor = getColor(dividerColor);
    [self addSubview:lineView1];
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(firstBtn.mas_right).offset(5 / WIDTH_6S_SCALE);
        make.centerY.equalTo(firstBtn.mas_centerY);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(firstBtn.mas_height);
    }];
}
@end

